package com.example.feign.controller;

import com.example.feign.entity.Type;
import com.example.feign.feign.TypeFeign;
import com.example.feign.util.EntityToMap;
import com.example.feign.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/type")
public class TypeFeignController {

    @Autowired
    TypeFeign typeFeign;


    @GetMapping("/get")
    public Response getType(
            @RequestParam(value = "page",required = false) Integer page,
            @RequestParam(value = "size",required = false) Integer size,
            Type type){
        Map map = new HashMap<>();
        map = EntityToMap.object2Map(type);
        return typeFeign.getType(page, size, map);
    }

    @GetMapping("/getAll")
    public Response getAllType(){
        return typeFeign.getAllType();
    }

    @PostMapping("/add")
    public Response addType(Type type){
        return typeFeign.addType(type);
    }

    @PutMapping("/update")
    public Response updateType(Type type){
        return typeFeign.updateType(type);
    }

    @PutMapping("/del")
    public Response delType(@RequestParam(value = "typeId",required = true) String typeId){
        return typeFeign.delType(typeId);
    }

}
